<?php
/*
 * 常用函数
 */

/**
 * 跳转
 *
 * @param str $sUrl
 */
function f_goto($sUrl){
	header("Location: ".$sUrl);
	exit;
}

/**
 * 获取当前访问的完整url地址
 */
function f_getCurUrl(){
	$url='http://';
	if(isset($_SERVER['HTTPS'])&&$_SERVER['HTTPS']=='on'){
		$url='https://';
	}
	
	if (strpos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false){
		if($_SERVER['SERVER_PORT']!='80'){
			$url.=$_SERVER['HTTP_HOST'].':'.$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI'];
		}else{
			$url.=$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
		}
	} else {
		if($_SERVER['SERVER_PORT']!='80'){
			$url.=$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI'];
		}else{
			$url.=$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
		}
	}
	return $url;
}

/**
 * 取得当前IP, 默认ip2long转化成int
 * 
 * @param bool $bIsSee  是否显示可视的IP  如 127.0.0.1
 * @return int
 */
function f_getIp($bIsSee= false){
	if ($bIsSee){
		return get_client_ip();
	}
	return ip2long(get_client_ip());
}

/**
 * 将intIP转化成可视化的IP
 *
 * @param int $nIp int的ip  如 127.0.0.1
 * @return str
 */
function f_getIpFromIn($nIp){
	return long2ip($nIp);
}

/**
 * 输入编码 utf8 防止乱码
 *
 * @return void
 */
function f_debug_utf8(){
	echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
}

/**
 * 输出换行  如html <br />
 *
 * @param int $n <br /> 个数
 * @return void
 */
function f_debug_br($n=1){
	for ($i=0;$i<$n;$i++){
		echo '<br />'."\n";
	}
}

/**
 * 输出分隔符  如html <br />
 *
 * @return void
 */
function f_debug_hr(){
	echo '<hr >'."\n";
}